package com.loongtech.bi.action.game;

import com.loongtech.bi.action.BaseBiSearchAction;
import com.loongtech.bi.manager.game.LevelGameManager;
import com.loongtech.bi.manager.game.LevelGameManager.ActiveUser10LevelDistributeData;
import com.loongtech.bi.manager.game.LevelGameManager.ActiveUser1LevelDistributeData;
import com.loongtech.bi.manager.game.LevelGameManager.NewUser1LevelDistributeData;
import com.loongtech.bi.manager.game.LevelGameManager.UserSevenLoss1LevelDistributeData;
import com.loongtech.bi.manager.system.SysLogManager;
import com.loongtech.bi.support.Session;
import com.loongtech.bi.support.chart.ChartTool;
import com.loongtech.bi.support.chart.ChartType;
import com.loongtech.bi.support.chart.ChartUIData;
import com.loongtech.core.util.Time;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import javax.annotation.PostConstruct;
import java.util.Date;
import java.util.List;

/**
 * 游戏内分析-等级分析Action
 * @author Marin
 * @date 2015年09月17日
 */
@Controller
@Scope("view")
public class LevelUserGameAction extends BaseBiSearchAction {
	private static final long serialVersionUID = 1L;
    private Date dayDate = new Date(Time.getBeginningOfDay(Time.currentTime() - Time.DAY));  // 前端传过来的开始时间

    private List<ActiveUser1LevelDistributeData> dataList1;  // 前端要显示的数据1
    private ChartUIData chartData1;  // 前端要显示的柱状图1数据

    private List<ActiveUser10LevelDistributeData> dataList2;  // 前端要显示的数据1
    private ChartUIData chartData2;  // 前端要显示的柱状图1数据

    private List<NewUser1LevelDistributeData> dataList3;  // 前端要显示的数据1
    private ChartUIData chartData3;  // 前端要显示的柱状图1数据

    private List<UserSevenLoss1LevelDistributeData> dataList4;  // 前端要显示的数据1
    private ChartUIData chartData4;  // 前端要显示的柱状图1数据

    private List<LevelGameManager.NewUser1LevelDistributeData1> dataList100;
    private ChartUIData chartData100;

    @Autowired
    private LevelGameManager levelGameManager;

    @Autowired
    private SysLogManager sysLogManager;
    @Autowired
    private Session session;

    @PostConstruct
    public void init() {
        search();
        newSearch();
    }

    public void search() {
        sysLogManager.addLog(session.getUserName(), "游戏内分析-用户等级分析");

        chartData100 = null;
        chartData1 = null;
        chartData2= null;

        dataList1 = levelGameManager.getActiveUser1LevelDistributeData(dayDate, queryPlatform, queryChannel, queryServer);
        if (dataList1 != null && dataList1.size() > 0) {
            chartData1 = new ChartUIData();
            chartData1.setJsonType(ChartType.SPLINE.type);
            chartData1.setJsonStr(new ChartTool(dataList1, ActiveUser1LevelDistributeData.class, "").loadData(chartData1.getJsonType(), true));
        }

        dataList2 = levelGameManager.getActiveUser10LevelDistributeData(dayDate,queryPlatform, queryChannel, queryServer);
        if (dataList2 != null && dataList2.size() > 0) {
            chartData2 = new ChartUIData();
            chartData2.setJsonType(ChartType.COLUMN.type);
            chartData2.setJsonStr(new ChartTool(dataList2, ActiveUser10LevelDistributeData.class, "").loadData(chartData2.getJsonType(), true));
        }

        dataList100 = levelGameManager.getNewUser1LevelDistributeData1(dayDate, queryPlatform, queryChannel, queryServer);
        if (dataList100 != null && dataList100.size() > 0) {
            chartData100 = new ChartUIData();
            chartData100.setJsonType(ChartType.SPLINE.type);
            chartData100.setJsonStr(new ChartTool(dataList100, LevelGameManager.NewUser1LevelDistributeData1.class, "").loadData(chartData100.getJsonType(), true));
        }
    }

    /**
     * 新查询
     */
    public void newSearch() {
        chartData3 = null;
        chartData4= null;

        dataList3 = levelGameManager.getNewUser1LevelDistributeData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer);
        if (dataList3 != null && dataList3.size() > 0) {
            chartData3 = new ChartUIData();
            chartData3.setJsonType(ChartType.SPLINE.type);
            chartData3.setJsonStr(new ChartTool(dataList3, NewUser1LevelDistributeData.class, "").loadData(chartData3.getJsonType(), true));
        }

        dataList4 = levelGameManager.getUserSecondLoss1LevelDistributeData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer);
        if (dataList4 != null && dataList4.size() > 0) {
            chartData4 = new ChartUIData();
            chartData4.setJsonType(ChartType.SPLINE.type);
            chartData4.setJsonStr(new ChartTool(dataList4, UserSevenLoss1LevelDistributeData.class, "").loadData(chartData4.getJsonType(), true));
        }
    }

    @Override
    protected String csvContent() {
        return "等级分布";
    }

    @Override
    protected String csvFileName() {
        return "等级分布";
    }

    public Date getDayDate() {
        return dayDate;
    }

    public void setDayDate(Date dayDate) {
        this.dayDate = dayDate;
    }

    public List<ActiveUser1LevelDistributeData> getDataList1() {
        return dataList1;
    }

    public void setDataList1(List<ActiveUser1LevelDistributeData> dataList1) {
        this.dataList1 = dataList1;
    }

    public ChartUIData getChartData1() {
        return chartData1;
    }

    public void setChartData1(ChartUIData chartData1) {
        this.chartData1 = chartData1;
    }

    public List<ActiveUser10LevelDistributeData> getDataList2() {
        return dataList2;
    }

    public void setDataList2(List<ActiveUser10LevelDistributeData> dataList2) {
        this.dataList2 = dataList2;
    }

    public ChartUIData getChartData2() {
        return chartData2;
    }

    public void setChartData2(ChartUIData chartData2) {
        this.chartData2 = chartData2;
    }

    public List<NewUser1LevelDistributeData> getDataList3() {
        return dataList3;
    }

    public void setDataList3(List<NewUser1LevelDistributeData> dataList3) {
        this.dataList3 = dataList3;
    }

    public ChartUIData getChartData3() {
        return chartData3;
    }

    public void setChartData3(ChartUIData chartData3) {
        this.chartData3 = chartData3;
    }

    public List<UserSevenLoss1LevelDistributeData> getDataList4() {
        return dataList4;
    }

    public void setDataList4(List<UserSevenLoss1LevelDistributeData> dataList4) {
        this.dataList4 = dataList4;
    }

    public ChartUIData getChartData4() {
        return chartData4;
    }

    public void setChartData4(ChartUIData chartData4) {
        this.chartData4 = chartData4;
    }

    public List<LevelGameManager.NewUser1LevelDistributeData1> getDataList100() {
        return dataList100;
    }

    public void setDataList100(List<LevelGameManager.NewUser1LevelDistributeData1> dataList100) {
        this.dataList100 = dataList100;
    }

    public ChartUIData getChartData100() {
        return chartData100;
    }

    public void setChartData100(ChartUIData chartData100) {
        this.chartData100 = chartData100;
    }
}
